package com.shujia.MR.wordcount;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;

import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.FileInputStream;
import java.io.IOException;

public class MyWordCountDriver {
    public static void main(String[] args) throws IOException, InterruptedException, ClassNotFoundException {

        Configuration conf = new Configuration();
        // 创建一个Job
        Job job = Job.getInstance(conf);

        job.setJarByClass(MyWordCountDriver.class);
        job.setJobName("MyWordCount");

        // 设置Mapper及Reducer类
        job.setMapperClass(MyWrodCountMapper.class);
        job.setReducerClass(MyWordCountReducer.class);

        // 设置Map方法输出类型
        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(IntWritable.class);

        job.setNumReduceTasks(2);


        // 设置最终输出类型
        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(IntWritable.class);

        // 设置数据源以及输出结果,注意选择 org.apache.hadoop.mapreduce.lib.input.FileInputFormat
        FileInputFormat.addInputPath(job, new Path("D:\\workspace19\\HadoopCode\\data\\wordcount"));
        FileOutputFormat.setOutputPath(job, new Path("D:\\workspace19\\HadoopCode\\output\\wordcountoutput"));

        // 提交
        job.waitForCompletion(true);
    }
}
